#ifndef UDPCLI_H
#define UDPCLI_H

#include <list>

#include "enet/enet.h"
#include "udp-cli-api.h"

typedef struct tagDataBuf_S{
    UINT8 *puc_data;
    int    i_data_len;
}DataBuf_S;


class UdpCli
{
public:
    UdpCli();
    ~UdpCli() { pthread_mutex_destroy(&m_send_list_lock); }
    int init();
    int deinit(){ enet_host_destroy(client); }
    int create_socket(const char *pc_addr, UINT16 us_port);
    int send_udp_data(int i_type, UINT8 *puc_data, INT32 i_data_len);
    int disconnet();
    int get_send_list_size() { return mi_list_size; }
private:
    static void *send_list_run( void * arg );
    int send_list();
    int real_send(UINT8 *puc_data, INT32 i_data_len);
    void send_list_lock()    {pthread_mutex_lock(&m_send_list_lock);}
    void send_list_unlock()  {pthread_mutex_unlock(&m_send_list_lock);}

private:
    ENetHost * client;
    ENetAddress address;
    ENetEvent event;
    ENetPeer *peer;

    pthread_t m_send_list_tid;
    pthread_mutex_t m_send_list_lock;
    std::list<DataBuf_S>  m_send_list;
    int     mi_list_size;
    bool    mb_send_list_func_run;

};











#endif // UDPCLI_H
